package com.price.compare.common;


/**
 * Json数据统一包装类
 */
public class JsonResult<T> {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 状态文本
     */
    private String status;
    /**
     * 消息
     */
    private String msg;
    /**
     * 数据
     */
    private T data;

    public JsonResult() {
    }

    private JsonResult(Integer code, String status, String msg, T data) {
        this.code = code;
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static JsonResult ok() {
        return new JsonResult(1, "ok", "success", null);
    }

    public static JsonResult ok(String msg) {
        return new JsonResult(1, "ok", msg, null);
    }

    public static JsonResult ok(Object data) {
        return new JsonResult(1, "ok", "success", data);
    }

    public static JsonResult ok(String msg, Object data) {
        return new JsonResult(1, "ok", msg, data);
    }

    public static JsonResult error() {
        return new JsonResult(0, "error", "error", null);
    }

    public static JsonResult error(String msg) {
        return new JsonResult(0, "error", msg, null);
    }

    public static JsonResult error(String msg, Integer code) {
        return new JsonResult(code, "error", msg, null);
    }

    public static JsonResult error(String msg, Object data) {
        return new JsonResult(0, "error", msg, data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
